<!DOCTYPE html>

<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <title>校园互助</title>
    <link rel="stylesheet" href="/lib/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="/css/base.css">
    <link href="/index.css" rel="stylesheet">
    <link rel="stylesheet" href="/main.css">
    <link rel="stylesheet" href="/weather.css">
    <style>
        .form-container:first-child {
            margin-top: 0px;
        }
    </style>

</head>

<body>
    <!-- 头部 -->
    <div class="header">
        <!-- 网站标志 -->
        <div class="logo fl">
            <div class="logo fl">
                <i>校园互助</i>
            </div>
        </div>
        <!-- /网站标志 -->
        <!-- 用户信息 -->
        <div class="info">
            <div class="profile dropdown fr">
                <span class="btn dropdown-toggle" data-toggle="dropdown">
                    <div class="user_name">
                        <% if(session.user){%>
                            <span>欢迎你:<%= session.user %></span>
                <span class="caret"></span>
                <% } %>

            </div>

            </span>
            <div>
                <% if(!session.user){ %>
                    <a href="/signin">未登录,点击登录</a>
                    <span style="float: right; padding-right:40px ;"><a href="/signup">点击注册</a></span>
                    <% } %>
            </div>

            <ul class="dropdown-menu">
                <li><a href="/posts">主页</a></li>
                <li><span class="signout" style="display: block;padding-left:20px ;">退出</span></li>
            </ul>
        </div>
    </div>
    <!-- /用户信息 -->
    </div>
    <!-- /头部 -->

    <!-- 主体内容 -->
    <div class="content">
        <!-- 侧边栏 -->
        <div class="aside fl">
            <% if(session.user){ %>
                <ul class="menu list-unstyled">
                    <li>
                        <a class="item active" href="/posts">
                            <span class="glyphicon glyphicon-film"></span> 全部文章
                        </a>
                    </li>
                    <li>
                        <a class="item active" href="/create">
                            <span class="glyphicon glyphicon-user"></span> 发表文章
                        </a>
                    </li>
                    <li>
                        <a class="item active" href="/createup">
                            <span class="glyphicon glyphicon-hdd"></span> 发表悬赏贴
                        </a>
                    </li>
                    <li>
                        <a class="item active" href="/xsposts">
                            <span class="glyphicon glyphicon-hdd"></span>查看悬赏贴
                        </a>
                    </li>
                    <li>
                        <a class="item active" href="/personal">
                            <span class="glyphicon glyphicon-inbox"></span> 个人信息
                        </a>
                    </li>
                    <li>
                        <a class="item active" href="/showmyxs">
                            <span class="glyphicon glyphicon-inbox"></span> 查看个人接取的悬赏
                        </a>
                    </li>


                </ul>
                <% } %>
                    <% if(!session.user){ %>
                        <ul class="menu list-unstyled">
                            <li>
                                <a class="item active" href="/posts">
                                    <span class="glyphicon glyphicon-film"></span> 全部文章
                                </a>
                            </li>
                        </ul>
                        <% } %>
                            <div class="cprt">
                                Powered by <a href="#" target="_blank" style="color: #fff;">赵波，任滇杭，王首振</a>
                            </div>
        </div>
        <!-- 侧边栏 -->
        <div class="main">
            <!-- 分类标题 -->
            <div class="title">
                <h4>发表悬赏</h4>
            </div>
            <div class="back">
                <a title="回到顶部">
                    <img src="/img/less.png" width="70px" height="70px">
                </a>
            </div>
            <div class="show_weather">
                <p>
                    <span class="show_city"></span>
                    <span class="show_wendu"></span>
                    <span class="show_feng"></span>
                    <span class="show_zhiliang"></span>
                </p>
            </div>
            <!-- /分类标题 -->
            <div class="form-container">
                <div class="container">
                    <form method="post" class="form create">
                        <div>
                            <label>标题:</label>
                            <input class="input" placeholder="文章标题" type="text" name="title">
                        </div>
                        <div>
                            <label>内容:</label>
                            <textarea class="textarea" name="content" id="content" cols="42" rows="10"></textarea>
                        </div>
                        <div>
                            <label>悬赏金额:</label>
                            <input class="input" type="text" name="money">
                        </div>
                        <div class="submit">发表</div>
                    </form>
                </div>
            </div>
        </div>
    </div>
    <!-- /主体内容 -->
    <script src="/lib/jquery/dist/jquery.min.js"></script>
    <script src="/lib/bootstrap/js/bootstrap.min.js"></script>
    <script src="/lib/ckeditor5/ckeditor.js"></script>
    <script type="text/javascript" src="/js/weather.js"></script>
    <script type="text/javascript" src="/js/animate.js"></script>
    <script type="text/javascript" src="/js/signout.js"></script>
    <script type="text/javascript" src="http://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script type="text/javascript">
        $('.submit').click(() => {
            console.log($('.form').serialize());
            $.ajax({
                url: '/createup',
                data: $('.form').serialize(),
                type: 'post',
                dataType: 'json',
                cache: false,
                success: function(msg) {
                    if (msg) {
                        $('.success').text('发表悬赏成功');
                        fade('.success');
                        setTimeout(() => {
                            window.location.href = '/xsposts';
                        }, 1000);
                    } else {
                        $('.error').text('发表悬赏失败');
                        fade('.error');
                        setTimeout(() => {
                            window.location.reload();
                        }, 1000);
                    }
                },
                error: function() {
                    alert('发表文章出现异常');
                }
            });
        });
    </script>
</body>

</html>